﻿using System;
using System.Linq;
using ConsoleApplication16;

namespace ConsoleApplication19
{
    class Program3
    {
        public static void Main2()
        {
            Sum(0.Chain(_ => Unit.Create(_, _ + 2)),
                1.Chain(_ => Unit.Create(_, _ + 4)))
                .ToEnumerable().Take(10).ToList().ForEach(Console.WriteLine);
        }

        static Chain<int> Sum(Chain<int> chain1, Chain<int> chain2)
        {
            return () => {
                var unit1 = chain1();
                var unit2 = chain2();
                return Unit.Create(unit1.Value + unit2.Value, Sum(unit1.Next, unit2.Next));
            };
        }
    }
}